package handler

import (
	"context"
	"ctrip-travel/api/handler/request"
	"ctrip-travel/rpc/global"
	user1 "ctrip-travel/rpc/proto/user"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Register(c *gin.Context) {
	var req request.RegisterReq
	err := c.ShouldBind(&req)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "数据不能为空",
		})
		return
	}
	_, err = global.UserClient.Register(context.Background(), &user1.RegisterReq{
		Name: req.Name,
		Pass: req.Pass,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "注册失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "注册成功",
	})
}
